﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace doufu.WebUI.Helper
{
    public class StoryCategoryModel
    {
        public string id { get; set; }
        public bool hasEmpty { get; set; }
        public int? value { get; set; }
        public List<SelectListItem> Item { get; set; }
    }

    public static class StoryCategorySelector
    {

        static public void StoryCategory(this HtmlHelper html, string id = "category_id", int? value = null, bool hasEmpty = false)
        {
            var entity = new StoryCategoryModel
            {
                id = id,
                value = value,
                Item = new Service.CategoryService().List().Select(x => new SelectListItem
                {
                    Value = x.category_id.ToString(),
                    Text = x.category_name,
                    Selected = x.category_id == value
                }).ToList()
            };
            if (hasEmpty)
            {
                entity.Item.Insert(0, new SelectListItem { });
            }
            //var entity = new Service.CategoryService().List();
            html.RenderPartial("Helper/StoryCategorySelect", entity);

        }

    }
}
